using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Jonathan.Classes;

namespace Jonathan
{
	/// <summary>
	/// An object in our list control
	/// </summary>
    public class ListItem
    {
        #region - Variables -

        private string m_Text;
        private object m_Tag;
        private object m_Value;
        private Rectangle m_Bounds;
        private bool m_Selected;

        #endregion

        #region - Constructor -

        /// <summary>
        /// Creates a new ListItem
        /// </summary>
        /// <param name="text">String dislpayed on the ListItem...</param>
        public ListItem(string text)
        {
            this.m_Text = text;
            this.m_Value = null;
            this.m_Tag = null;
            this.m_Selected = false;

            this.m_Bounds = new Rectangle(2, 0, 0, 0);
        }

        #endregion

        #region - Properties -

        /// <summary>
        /// Gets or Sets the Text of the ListItem...
        /// </summary>
        public string Text
        {
            get { return this.m_Text; }

            set { this.m_Text = value; }
        }

        /// <summary>
        /// Gets or Sets the Value for the ListItem...
        /// </summary>
        public object Value
        {
            get { return this.m_Value; }

            set { this.m_Value = value; }
        }

        /// <summary>
        /// Gets or Sets a Data Object for the ListItem...
        /// </summary>
        public object Tag
        {
            get { return this.m_Tag; }

            set { this.m_Tag = value; }
        }

        /// <summary>
        /// Gets or Sets the Bounds of the ListItem...
        /// </summary>
        public Rectangle Bounds
        {
            get { return this.m_Bounds; }

            set { this.m_Bounds = value; }
        }

        /// <summary>
        /// Gets or Sets if the ListItem is Selected...
        /// </summary>
        public bool Selected
        {
            get { return this.m_Selected; }

            set { this.m_Selected = value; }
        }

        /// <summary>
        /// Gets or Sets the Left side of the ListItem...
        /// </summary>
        public int Left
        {
            get { return this.m_Bounds.X; }

            set { this.m_Bounds.X = value; }
        }

        /// <summary>
        /// Gets or Sets the Top side of the ListItem...
        /// </summary>
        public int Top
        {
            get { return this.m_Bounds.Y; }

            set { this.m_Bounds.Y = value; }
        }

        /// <summary>
        /// Gets or Sets the Width of the ListItem...
        /// </summary>
        public int Width
        {
            get { return this.m_Bounds.Width; }

            set { this.m_Bounds.Width = value; }
        }

        /// <summary>
        /// Gets or Sets the Height of the ListItem...
        /// </summary>
        public int Height
        {
            get { return this.m_Bounds.Height; }

            set { this.m_Bounds.Height = value; }
        }

        #endregion

        #region - Paint -

        internal void PaintItem(Graphics g, Font f)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            StringFormat fmt = new StringFormat();
            fmt.Trimming = StringTrimming.EllipsisCharacter;
            fmt.FormatFlags = StringFormatFlags.NoWrap;

            if (this.m_Selected)
            {
                LinearGradientBrush lgb = new LinearGradientBrush(this.m_Bounds, Color.White, Color.Silver,
                    /*Color.White, Color.LightBlue, */LinearGradientMode.Vertical);
                GraphicsPath p = Common.RoundRect(new Rectangle(2, this.m_Bounds.Y + 1, this.m_Bounds.Width - 2, this.m_Bounds.Height - 2), 1, 1, 1, 1);
                g.FillPath(lgb, p);
                g.DrawPath(Pens.Black/*Pens.Blue*/, p);
                g.DrawString(this.m_Text, new Font(f, FontStyle.Bold), Brushes.Black, 
                    new RectangleF(8, this.m_Bounds.Y + 1, this.m_Bounds.Width - 10, this.m_Bounds.Height - 2), fmt);
            }
            else
            {
                g.FillRectangle(Brushes.White, new Rectangle(1, this.m_Bounds.Y, this.m_Bounds.Width, this.m_Bounds.Height));
                g.DrawString(this.m_Text, f, Brushes.Black, 
                    new RectangleF(2, this.m_Bounds.Y + 1, this.m_Bounds.Width - 2, this.m_Bounds.Height - 2), fmt);
            }
        }

        #endregion
    }
}
